import http from "@/utils/http";
import type * as Role from "./type";

/**
 * 角色列表
 */
export const getRoleList = (params?: { name: string }) => {
  return http.get<Role.RoleList[]>("/sass/role/list", params);
};

/**
 * 新增角色
 */
export const addRole = (data: Role.RoleInfo) => {
  return http.post("/sass/role/add", data);
};

/**
 * 修改角色
 */
export const editRole = (data: Role.RoleInfo, roleId: string) => {
  return http.put(`/sass/role/update/${roleId}`, data);
};

/**
 * 删除角色
 */
export const deleteRole = (roleId: string) => {
  return http.deleteMethod(`/sass/role/delete/${roleId}`);
};
/**
 * 查询角色对应人员
 */
export const rolePersonnelList = (data: { name: string }, roleId: string) => {
  return http.get<Role.RolePersonnelList>(`/sass/role/userList/${roleId}`, data);
};

/**
 * 查询角色对应菜单
 */
export const roleMenuList = (roleId: string) => {
  return http.get<Role.RoleMenuList>(`/sass/role/getMenuList/${roleId}`);
};
// 查询角色对应菜单id
export const roleMenuListId= (roleId: string) => {
  return http.get(`/sass/role/detail/${roleId}`);
};
/**
 * 为角色添加成员
 */
export const addRoleUser = (userIds: string[], roleId: string) => {
  return http.post(`/sass/role/saveUser/${roleId}`, userIds);
};

/**
 * 角色添加成员——搜索成员
 */
export const searchRoleUser = (data: { deptId: string; name: string }) => {
  return http.get<Role.RoleSearchPersonnel[]>("/sass/role/search/user", data);
};
// 删除角色人员
export const delRoleUser=(roleId:string,userId:string[])=>{
  return http.post(`sass/role/deleteUser/${roleId}`,userId)
}

/**
 * 数据权限列表
 */
export const dataScopeList = () => {
  return http.get<Role.DataScopeList[]>("/sass/roleDataPermission/getDataPermissionList");
};
/**
 * 查询角色数据权限
 */
export const roleDataScopeList = (params:{ roleId: string }) => {
  return http.get<string[]>(`/sass/roleDataPermission/getRoleDataPermissionSetInfo`,params);
};
/**
 * 设置角色数据权限
 */
export const setRoleDataScope = (data: { roleId: string; settingId:string}) => {
  return http.put(`/sass/roleDataPermission/setRoleDataPermission/${data.roleId}/${data.settingId}`);
};
